package com.example.memory.entity;

import com.example.memory.util.FastImageInfo;
import com.example.memory.util.FileUtils;
import com.example.memory.util.FunctionUtils;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import com.example.memory.util.IDUtils;

@Data
public class File {
    private String id;
    private String cid;
    private String name;
    private String path;
    private String format;
    private int width;
    private int height;
    public static final String TABLE_NAME = "file";
    public static final String[] ALL_COLUMNS = {"`id`", "`name`", "`path`", "`format`"};
    public static final String ID_COLUMN = "`id`";
    public static final String ID_NAME = "id";
    public static final String FILEID_NAME = "fileid";
    public static final String NAME_COLUMN = "`name`";
    public static final String NAME_NAME = "name";
    public static final String PATH_COLUMN = "`path`";
    public static final String PATH_NAME = "path";
    public static final String FORMAT_COLUMN = "`format`";
    public static final String FORMAT_NAME = "format";

    public static File getInstance(MultipartFile multipartFile, String cid) {
        File file = new File();
        file.setId(IDUtils.getStringID());
        file.setName(multipartFile.getOriginalFilename());
        file.setFormat(FileUtils.img_video(file.getName()));
        file.setCid(cid);
        String nowDate = FunctionUtils.getNowDate();
        file.setPath(FileUtils.getPath(FileUtils.HOME, "files", nowDate, cid));
        return file;
    }
}
